package juc.demo3;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

public class Nosafe {

    public static void main(String[] args) {

        //写时复制技术,写的时候复制一个新容器，对新容器进行写，原容器不做操作，写完以后
        //再把原容器的引用指向新容器
        List list = new CopyOnWriteArrayList();
//        Set set = new CopyOnWriteArraySet();
//        Map map = new ConcurrentHashMap();

        for (int i = 1; i <=30; i++) {

            new Thread(() -> {
                list.add(UUID.randomUUID().toString().substring(0,4));
                System.out.println(list);
            },String.valueOf(i)).start();
        }

    }
}
